package com.huobao.yunying.adapters;

import com.huobao.yunying.entity.TemaiDetail;
import com.huobao.yunying.entity.TemaiDetail_goods_list;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.ImageUtils.OnImageLoadListener;
import com.huobao.yunying.utils.SkipUtils;
import com.huobao.yunying.views.NoScrollGridView;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.utils.ScreenUtil;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;

import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_Temai_Detail extends QuickAdapter<TemaiDetail> {
	public Adapter_Temai_Detail(Context context) {
		super(context, R.layout.item_temai_detail);
	}

	@Override
	protected void convert(BaseAdapterHelper helper, final TemaiDetail data) {
		final ImageView imageView = helper.getView(R.id.imageview);
		NoScrollGridView gridView = helper.getView(R.id.gridview);
		ImageUtils.loadimg(imageView, data.getRecom_logo(), new OnImageLoadListener() {

			@Override
			public void onLoadSuccess(Drawable drawable) {
				int newWidth = ScreenUtil.getInstant().getDisWidth(context);
				int newHight = newWidth * drawable.getIntrinsicHeight() / drawable.getIntrinsicWidth();
				LayoutParams layoutParams = new LayoutParams(newWidth, newHight);
				imageView.setLayoutParams(layoutParams);
			}
		});
		if (data.getGoods_list() != null) {
			Adapter_Temai_Detail_GridView adapter = new Adapter_Temai_Detail_GridView(context, data.getGoods_list());
			gridView.setAdapter(adapter);
		}
		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				TemaiDetail_goods_list detail = data.getGoods_list().get(position);
				SkipUtils.seeDetailForResult((Activity) context, detail.getGoods_id(), detail.getDefault_image());
			}
		});
		imageView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				if (TextUtils.isEmpty(data.getKeywords()) && TextUtils.isEmpty(data.getBrand()))
					return;
				SkipUtils.skipToSearchList(context, null, TextUtils.isEmpty(data.getKeywords()) ? null : data.getKeywords(), null, null, TextUtils.isEmpty(data.getBrand()) ? null : data.getBrand(), null);
			}
		});
	}

}
